from typing import Optional as Op, List,Dict

class LLMReasoner:
    """ LLM-based reasoning class for handling user commands and device interactions.(ReAct agent) """

    def __init__(
            self,
            llm_provider: str = 'openai',
            model_name : Op[str] = None,
            api_key: Op[str] = None,
            temperature : float = 0.2,
            max_tokens: int = 2000,
            vision: bool = False,
            base_url: Op[str] = None,
    ):
        """
        Initializes the LLMReasoner with necessary configurations.
        """
        pass


    async def reason(
            self,
            goal : str,
            history: List[Dict[str, str]] = [],
            available_tools: Op[List[str]] = None,
            screenshot_data : Op[bytes] = None,
    ) -> Dict[str, str]:
        """
        Main reasoning method that interacts with the LLM to process the command and device interactions.
        Returns:
            Dict[str, str]: A dictionary containing the command and any additional information.
        """
        # This is a placeholder for actual reasoning logic
        return {"command": "example_command", "info": "example_info"}

    def _create_system_prompt(self,available_tools : Op[List[str]] = None) -> str:
        """
        Creates a system prompt for the LLM.
        Returns:
            str: The system prompt.
        """
        return "You are a helpful assistant that can reason about user commands and device interactions."
    
    def _create_user_prompt(self,goal: str,history: List[Dict[str, str]]) -> str:
        """
        Creates a user prompt for the LLM based on the goal and history.
        Args:
            goal (str): The user's goal.
            history (List[Dict[str, str]]): The conversation history.
        Returns:
            str: The user prompt.
        """
        return f"User's goal: {goal}\nConversation history: {history}"
    

    def _parse_response(self, response : str) -> Dict[str, str]:
        """
        Parses the LLM response to extract the command and any additional information.
        Args:
            response (str): The response from the LLM.
        Returns:
            Dict[str, str]: A dictionary containing the command and additional information.
        """
        # This is a placeholder for actual parsing logic
        return {"command": response, "info": ""}
